/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jz.dynadatasorces.controller;

//import com.jz.dynadatasorces.po.User;
//import com.jz.dynadatasorces.service.UserService;

import com.jz.dynadatasorces.mapper.LcUserMapper;
import com.jz.dynadatasorces.po.LcUser;
import com.jz.dynadatasorces.po.Order;
import com.jz.dynadatasorces.po.UserZx;
//import com.jz.dynadatasorces.service.UserZxService;
import com.jz.dynadatasorces.po.vo.OrderVo;
import com.jz.dynadatasorces.po.vo.QueryOrderVo;
import com.jz.dynadatasorces.rocketMQ.producer.Myproducer;
import com.jz.dynadatasorces.service.LcUserService;
import com.jz.dynadatasorces.service.UserZxService;
import com.jz.dynadatasorces.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
 */
@RequestMapping("/test")
@RestController
public class BasicController {
    @Resource
    private OrderServiceImpl orderServiceImpl;
    @Autowired
    private UserZxService userZxService;
    @Autowired
    Myproducer myproducer;
    @Autowired
    private LcUserService lcUserService;

    @PostMapping("/hello")
    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
        return "Hello " + name;
    }


    @PostMapping("/user")

    public List<UserZx> user() {
        List<UserZx> allUsers = userZxService.list();
        return allUsers;

    }

    @PostMapping("/order")

    public List<Order> order() {
        List<Order> allUsers = orderServiceImpl.list();
        return allUsers;

    }

    @PostMapping("/user2")

    public List<LcUser> user2() {
        List<LcUser> list = lcUserService.list();
        return list;

    }

    @PostMapping("/QueryOrderVo")

    public List<OrderVo> QueryOrderVo(@RequestBody QueryOrderVo queryOrderVo) {
        List<OrderVo> list = orderServiceImpl.ListOrder(queryOrderVo);
        for (OrderVo orderVo : list) {

        }
        return list;
    }

    @PostMapping("/testRocket")
    public String testRocket() {
        List<OrderVo> list = new ArrayList<>();
        OrderVo orderVo = new OrderVo();
        orderVo.setCscode("123");
        OrderVo orderVo1 = new OrderVo();
        orderVo.setCscode("456");
        list.add(orderVo);
        list.add(orderVo1);
        for (OrderVo vo : list) {
            myproducer.sendMessageInTransaction("topic5", "订单发送成功", vo);
        }
        return "订单发送成功";
    }


}
